package org.yray;

        import org.springframework.batch.core.Job;
        import org.springframework.batch.core.Step;
        import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
        import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
        import org.springframework.batch.item.ItemProcessor;
        import org.springframework.batch.item.database.JdbcBatchItemWriter;
        import org.springframework.batch.item.file.FlatFileItemReader;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.beans.factory.annotation.Qualifier;
        import org.springframework.context.annotation.Bean;
        import org.springframework.stereotype.Component;

/**
 * @author 这个码农不太萌
 */
@Component
public class DemoJob {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    @Qualifier("userReader")
    FlatFileItemReader<User> userReader;

    @Autowired
    @Qualifier("orgInfoProcess")
    ItemProcessor<User, User> orgInfoProcess;

    @Autowired
    @Qualifier("userWriter")
    JdbcBatchItemWriter<User> userWriter;

    @Bean
    public Job userJob() {
        return jobBuilderFactory.get("userJob")
                .start(userStep())
                .build();
    }

    public Step userStep() {
        return stepBuilderFactory.get("userStep")
                .<User,User>chunk(100)
                .reader(userReader)
                .processor(orgInfoProcess)
                .writer(userWriter)
                .build();
    }

}